//
//  UIViewController+tableView.m
//  zxc
//
//  Created by 李李善 on 2018/1/11.
//  Copyright © 2018年 李李善. All rights reserved.
//

#import "UIViewController+tableView.h"
#import <objc/runtime.h>
#import "UIViewController+Action.h"
#import "UIViewController+page.h"
static char * vHeader = "Header";
static char * vFooder = "Fooder";
@implementation UIViewController (tableView)

-(BOOL)isAddMJRefreshFooder
{
    return objc_getAssociatedObject(self, vFooder);
}
-(void)setIsAddMJRefreshFooder:(BOOL)isAddMJRefreshFooder
{
    objc_setAssociatedObject(self, vFooder,@(isAddMJRefreshFooder), OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}

-(BOOL)isAddMJRefreshHeader
{
    return objc_getAssociatedObject(self, vHeader);
}
-(void)setIsAddMJRefreshHeader:(BOOL)isAddMJRefreshHeader
{
    objc_setAssociatedObject(self, vHeader,@(isAddMJRefreshHeader), OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}

-(void)onSetSubviewSELForviewHeader:(UIView*)view forTableView:(UITableView *)tableView forSection:(NSInteger)section
{
    
}
- (void)onUpdateHeaderView:(BaseTableViewHeaderFooterView *_Nullable )view model:(id _Nullable)model atSection:(NSInteger)section
{
    __weak UIViewController *vc = self;
    [view update:model forTableView:vc.tableView AtSection:section];
}
- (void)onUpdateFooderView:(BaseTableViewHeaderFooterView * _Nullable)view model:(id _Nullable)model atSection:(NSInteger)section
{
    __weak UIViewController *vc = self;
    [view update:model forTableView:vc.tableView AtSection:section];
}


/** < 只更新屏幕内单元格数据，缓解卡顿状态 > */
#pragma mark -----Cell

-(void)onSetSubviewSELForViewFooder:(UITableViewHeaderFooterView*)view forTableView:(UITableView *)tableView forSection:(NSInteger)section
{
    
}
-(void)onSetSubviewSELForCell:(BaseTableViewCell *)cell forTableView:(UITableView *)tableView forIndexPath:(NSIndexPath *)indexPath
{
    
}

-(NSIndexPath *)indexPathForSubClass:(UIView *)view{
    UITableViewCell *cell = view.findTableViewCell;
    return [self.tableView indexPathForCell:cell];
}

- (void)onInsertItemsIntoBack:(NSInteger )itemCount
{
    
    if (0 == itemCount) {
        return;
    }
    NSInteger section = self.insertBackSection;
    UITableViewController *vc = (id)self;
    NSInteger rowCount = [vc tableView:self.tableView numberOfRowsInSection:section];
    
    NSMutableArray *arr = [[NSMutableArray alloc]initWithCapacity:itemCount];
    for (int n = 0; n < itemCount; ++n) {
     
        NSIndexPath *idxp = [NSIndexPath indexPathForItem:n+rowCount inSection:section];
        [arr addObject:idxp];
    }
        [self.tableView insertRowsAtIndexPaths:arr withRowAnimation:UITableViewRowAnimationFade];
    
    
}
-(MCCellInfo *)tableView:(UITableView *)tableView cellForIndexPath:(NSIndexPath *)indexPath IsHeight:(BOOL)isheight
{
    float screenH = [[UIScreen mainScreen] bounds].size.height;
    float kHratio =screenH / 667.0;
    MCCellInfo *info =[MCCellInfo configForCellId:cell0 Class:[BaseTableViewCell class] Height:kHratio *44 TableView:tableView];
    return info;
}

-(MCHFViewInfo *)tableView:(UITableView *)tableView HeaderInSection:(NSInteger)section isBiao:(BOOL)isBiao
{
    return [MCHFViewInfo configForViewId:header1 Class:[BaseTableViewHeaderFooterView class] Height:CGFLOAT_MIN TableView:tableView IsBian:isBiao];
}
-(MCHFViewInfo *)tableView:(UITableView *)tableView FooderInSection:(NSInteger)section isBiao:(BOOL)isBiao
{
    return [MCHFViewInfo configForViewId:foodter Class:[BaseTableViewHeaderFooterView class] Height:CGFLOAT_MIN TableView:tableView IsBian:isBiao];
}

-(id _Nullable)cellInitForSourceAtIndexPath:(NSIndexPath *_Nullable)indexPath
{
     return nil;
}

-(id _Nullable)headerInitForSourceAtSection:(NSInteger)section
{
     return nil;
}
-(id _Nullable)headerViewModelForSection:(NSInteger)section
{
    return nil;
}

-(id _Nullable)fooderInitForSourceAtSection:(NSInteger)section
{
    return nil;
}
-(id _Nullable)fooderViewModelForSection:(NSInteger)section
{
    return nil;
}


@end
